<?php

include 'config.php';
include '../common.php';

if (is_file('install.php')) {
  note('Deleting install.php');
  unlink('install.php');
 }

note('Changing permissions on config.php');
exec('chmod 755 config.php');

note('Renaming cron');
$dirname = randomWord();
exec('mkdir -p '          . $dirname);
exec('chmod -R 755 '      . $dirname);
exec('cp cron/index.php ' . $dirname);
exec('cp cron/last.txt '  . $dirname);
exec('rm -rf cron');

$s = $_SERVER['PHP_SELF'];
$s = preg_replace('/\/[^\/]+$/','',$s);
$url = 'http://' . $_SERVER['SERVER_NAME'] . $s . '/' . $dirname;
note('You new cron is <a href="' . $dirname . '">' . $url . '</a>');
note('You may run this file using the following:');

echo '<blockquote>';
echo '<code>curl -s ' . $url . '</code>';
echo '</blockquote>';
echo 'And mail photos to';
echo '<blockquote>';
echo '<a href="mailto:' . config('username') . '">' . config('username') . '</a>';
echo '</blockquote>';

?>